<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('导入&创建学习资料')" />
    <th:block th:include="include :: select2-css" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-material-add">
        <input name="ids" th:value="${ids}" type="hidden"/>
        <div class="form-group">
            <label class="col-sm-3 control-label">学习资料：</label>
            <div class="col-sm-8">
                <div class="col-sm-8">
                    <select class="form-control noselect2" id="materialId" name="materialId">
                        <option value="">-----选择学习资料-----</option>
                    </select>
                </div>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: select2-js" />
<script type="text/javascript">
        var prefix = ctx + "dict/spider"
        $("#form-material-add").validate({
            focusCleanup: true
        });

        $('#materialId').select2({
          ajax: {
            url: '/dict/material/search',
            dataType: 'json',
            delay: 250,
            processResults: function (data) {
               let rows = []
               data.rows.forEach(item => {
                  rows.push({
                    id: item.id,
                    text: item.name
                  })
               });
               return {
                 results: rows
               };
            }
          }
        });

        function submitHandler() {

             let data = $('#form-material-add').serializeArray()
             console.log(data);
             $.operate.save(prefix + "/materialOld", data);

        }
    </script>
</body>
</html>